/**
 * 
 */
window.onload = function (){
	setList('-1', choice_day);
}
console.log(resData);
// 用户选择哪天的记录
$('.tag_choice_day').on('click', '', function (){
	if($('.tag_choice_item').is(':hidden')){
		$('.tag_choice_item').show();
	}else{
		$('.tag_choice_item').hide();
	}
})

$('#id_order_list li').on('click', '', function (){
	$('#id_order_list li').removeClass('on');
	$(this).addClass('on');
	setList('-1', choice_day);
})

$('.tag_choice_close').on('click', '', function (){
	$('.tag_choice_item').hide();
})

$('.tag_putong_bet li').on('click', '', function (){
	$('.tag_putong_bet li').removeClass('on');
	$(this).addClass('on');
	var type = '';
	switch($(this).index().toString()){
		case '0':
			type = '-1';
			break;
		case '1':
			type = '2';
			break;
		case '2':
			type = '1';
			break;
		case '3':
			type = '0';
			break;
	}
	setList(type, choice_day );
})

// 查看哪个时间段的投注订单
var choice_day = 'today';
$('.tag_choice_item_li li').on('click', '', function (){
	var check = $(this).index();
	if(check == '0'){
		choice_day = 'today';
		$('.tag_choice_day').html('今天');
	}else if (check == '2'){
		choice_day = 'yesterday';
		$('.tag_choice_day').html('昨天');
	}else if (check == '4'){
		choice_day = '7day';
		$('.tag_choice_day').html('七天');
	}
	setList('-1', choice_day);
	$('.tag_choice_item').hide();
	// 重新初始化选项卡样式
	$('.tag_item').removeClass('on');
	$('.hd ul').children(':first').addClass('on');
})

$('.tag_close_detail').on('click', '', function (){
	$('.tag_bet_details').hide();
})

$('.tag_order_content').on('click', '.tag_show_detail', function (){
	$('#id_pt_bet_more, #id_chase_bet_more').hide();
	// 获取到点击目标投注的详细信息
	var detail = resData['list'][$(this).attr('amt')];
	// 初始化详细控件中的彩种样式
	$('.tag_lotter_cla').attr('class', 'fl iconfont tag_lotter_cla');
	$('.tag_lotter_cla').addClass(resData['cate'][resData['list'][$(this).attr('amt')]['cate_id']]['tags']);
	$('.tag_lott_title').html(detail.lott_title);
	var str = '';
	switch(detail.period[$(this).attr('amp')].status){
		case '1':
			str = '<span>未中奖</span>';
			break;
		case '2':
			str = '<span style="color: red;">已中奖</span>';
			break;
		default:
			str = '<span>未开奖</span>';
			break;
	}
	$('.tag_lott_winner').html(str);
	$('.tag_lott_period').html($(this).attr('amp'));
	console.log(detail);
	var paisongjiangjin = '';
	if(detail.is_chase == '1'){
		// 计算追号进度与追号金额
		var preiod_count   = 0;
		var jindu_index    = 0;
		var base_bet_money = 0;
		var id_winner_end  = '直追';
		$.each(detail.period, function (ji, jv){
			if(jv[0].winner != '0') jindu_index++;
			if(jv[0].winner_end == '1') id_winner_end = '中奖即停'; 
			preiod_count++;
			if(base_bet_money == 0){
				$.each(jv, function (ji1, jv1){
					base_bet_money += parseFloat(jv1.item_money);
				})
			}
		})
		$('.tag_bet_time:eq(1)').html(detail.re_createtime);
		$('.tag_bet_order_no:eq(1)').html(detail.order_no);
		$('.tag_bet_jindu').html('已追' + jindu_index + '期/总' + preiod_count + '期');
		$('.tag_chase_amount').html((parseFloat(detail.amount) - base_bet_money).toFixed(2));
		$('.tag_bet_amount:eq(1)').html(base_bet_money.toFixed(2));
		
		switch(detail.status){
			case '1':
				paisongjiangjin = '未中奖';
				break;
			case '2':
				var detailPrize = parseInt(detail.prize);
				paisongjiangjin = detailPrize > 0 ? detail.prize : '已中奖';
				break;
			default:
				paisongjiangjin = '未开奖';
				break;
		}
		
		$('.tag_bet_prize:eq(1)').html(paisongjiangjin);
		$('.tag_win_end').html(id_winner_end);
		$('#id_chase_bet_more').show();
	}else{
		$('.tag_bet_time:eq(0)').html(detail.re_createtime);
		$('.tag_bet_order_no:eq(0)').html(detail.order_no);
		$('.tag_bet_amount:eq(0)').html(detail.amount);
		var detailPrize  = parseInt(detail.prize);
		var winnerStatus = '';
		var openCode = detail.period[$(this).attr('amp')][0].kj_code;
		switch(detail.status){
			case '1':
				paisongjiangjin = '未中奖';
				break;
			case '2':
				var detailPrize = parseInt(detail.prize);
				paisongjiangjin = detailPrize > 0 ? detail.prize : '已中奖';
				break;
			default:
				paisongjiangjin = '未开奖';
				break;
		}
		$('.tag_bet_prize:eq(0)').html(paisongjiangjin);
		$('#id_pt_bet_more').show();
	}
	
	$('.tag_my_bet').html(function (){
		var str     = '<li></li>';
		var p_index = '';
		$.each(detail.period, function (i, v){
			$.each(v, function (i1, v1){
				if($.isEmptyObject(detail.is_chase) || detail.is_chase == '0'){
					// 普通投注
					str += '<li>';
					str += '	<div>' + v1.betting_no + '</div>';
					str += '	<span>' + v1.cn_play + '</span>';
					if(v.winner == '2'){
						str += '<span class="fr">奖金：' + v1.prize + '</span>';
					}
					str += '	<p class="hr1px"></p>';
					str += '</li>';
				}else{
					if(p_index != i){
						// 追号只显示期数， 不显示具体投注，具体投注在页面上面部分
						if($.isEmptyObject(v1.kj_code)) v1.kj_code = '未开奖';
						str += '<li>';
						str += '	<div>开奖号码：' + v1.kj_code + '</div>';
						str += '	<span>' + i + '</span>';
						if(v.winner == '2'){
							str += '<span class="fr">奖金：' + v1.prize + '</span>';
						}
						str += '	<p class="hr1px"></p>';
						str += '</li>';
						p_index = i;
					}
				}
			})
		})
		str    += '<li></li>';
		return str;
	})
	
	// 获取开奖信息
	$('.tag_bet_details').show();
})
